/**
 * @author: jw
 */

/**
 * @description 保存为经典案例
 */
export const changeClassic = {
  name: "保存为经典案例",
  url: "/app/change/classic",
  method: "get",
  requestDemo: {},
  responseDemo: {
    code: 1,
    message: "SUCCESS",
    data: {}
  },
  packagingRequest: function (param) {
    return {
      params: param,
      url: this.url, //.replace("{id}", param.id),
      method: this.method
    };
  },
  packagingResponse(res) {
    return res;
  }
};

/**
 * @description 复制应用
 */
export const copy = {
  name: "复制应用",
  url: "/app/copy",
  method: "get",
  requestDemo: {},
  responseDemo: {
    code: 1,
    message: "SUCCESS",
    data: {}
  },
  packagingRequest: function (param) {
    return {
      params: param,
      url: this.url,
      method: this.method
    };
  },
  packagingResponse(res) {
    return res;
  }
};
/**
 * @description 保存应用
 */
export const save = {
  name: "保存应用",
  url: "/app/saveOrUpdate",
  method: "post",
  requestDemo: {},
  responseDemo: {
    code: 1,
    message: "SUCCESS",
    data: {}
  },
  packagingRequest: function (param) {
    return {
      data: param,
      url: this.url,
      method: this.method
    };
  },
  packagingResponse(res) {
    return res;
  }
};

/**
 * @description 获取详情
 */
export const get = {
  name: "获取应用",
  url: "/app/{id}",
  method: "get",
  requestDemo: {},
  responseDemo: {
    code: 1,
    message: "SUCCESS",
    data: {}
  },
  packagingRequest: function (param) {
    return {
      params: param,
      url: this.url.replace("{id}", param.id),
      method: this.method
    };
  },
  packagingResponse(res) {
    return res;
  }
};

/**
 * @description 获取列表
 */
export const getList = {
  name: "获取应用列表",
  url: "/app/page",
  method: "get",
  requestDemo: {},
  responseDemo: {
    code: 1,
    message: "SUCCESS",
    data: {}
  },
  packagingRequest: function (param) {
    return {
      params: param,
      url: this.url,
      method: this.method
    };
  },
  packagingResponse(res) {
    return res;
  }
};

/**
 * @description 删除
 */
export const remove = {
  name: "删除应用",
  url: "/app/delete/{id}",
  method: "post",
  requestDemo: {},
  responseDemo: {
    code: 1,
    message: "SUCCESS",
    data: {}
  },
  packagingRequest: function (param) {
    return {
      params: param,
      url: this.url.replace("{id}", param.id),
      method: this.method
    };
  },
  packagingResponse(res) {
    return res;
  }
};

/**
 * @description 发布应用
 */
export const publish = {
  name: "发布应用",
  url: "/app/publish",
  method: "get",
  requestDemo: {},
  responseDemo: {
    code: 1,
    message: "SUCCESS",
    data: {}
  },
  packagingRequest: function (param) {
    return {
      params: param,
      url: this.url,
      method: this.method
    };
  },
  packagingResponse(res) {
    return res;
  }
};

/**
 * @description 应用上传
 */
export const uploadApp = {
  name: "应用上传",
  url: "/app/uploadApp",
  method: "post",
  requestDemo: {},
  responseDemo: {
    code: 1,
    message: "SUCCESS",
    data: {}
  },
  packagingRequest: function (param) {
    let formData = new FormData();
    formData.append("file", param.file);
    formData.append("applicationName", param.applicationName || "");
    formData.append("note", param.note || "");
    return {
      data: formData,
      url: this.url,
      method: this.method
    };
  },
  packagingResponse(res) {
    return res;
  }
};
/**
 * @description 文件上传
 */
export const uploadFile = {
  name: "文件上传",
  url: "/app/upload/{id}/{path}",
  method: "post",
  requestDemo: {},
  responseDemo: {
    code: 1,
    message: "SUCCESS",
    data: {}
  },
  packagingRequest: function (param) {
    let formData = new FormData();
    for (let i = 0; i < param.fileList.length; i++) {
      formData.append("fileList", param.fileList[i]);
    }
    let url = this.url.replace("{id}", param.id);
    url = url.replace("{path}", param.filePath);
    return {
      data: formData,
      url: url,
      method: this.method
    };
  },
  packagingResponse(res) {
    return res;
  }
};
